package com.langangkj.tools.redis.handler;

import com.langangkj.tools.redis.handler.provider.RedisSyncKeyProvider;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.data.redis.connection.DataType;

/**
 * @author ZhouChuGang
 * @version 1.0
 * @project redis-sync-tools
 * @date 2020/4/26 9:46
 * @Description 抽象的redis key 处理者
 */
public abstract class AbstractRedisKeyMetaHandler implements RedisKeyMetaHandler, BeanPostProcessor {

    @Autowired
    private RedisSyncKeyProvider redisSyncKeyProvider;

    /**
     * 各个子类返回自己支持的数据类型
     *
     * @return
     */
    protected abstract DataType getSupportDataType();

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        redisSyncKeyProvider.getTypeRedisKeyMetaHandlerMap().put(getSupportDataType(), this);
        return bean;
    }
}
